﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using DSAClient.Core;
using FSLib.App.SimpleUpdater;
using FSLib.App.SimpleUpdater.Wrapper;

namespace DSAClient
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            #region 注释
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //AppReportManager.Instance.AddListener<QiniuUploadLog>(doLog);
            //AppReportManager.Instance.AddListener<QiniuUploadResult>(doResult);
            ////new QiniuUploadTask(@"D:\pic_test\test.jpg").Run(null);
            //BackgroundWorker bk = new BackgroundWorker();
            //bk.DoWork += delegate
            //                 {
            //                     QiniuUploadTaskManager manager = new QiniuUploadTaskManager();
            //                     List<string> imgs = new List<string>(Directory.GetFiles(@"D:\pic_test"));
            //                     Stopwatch stopwatch = new Stopwatch();
            //                     stopwatch.Start();
            //                     manager.Run(imgs, "", 1);
            //                     stopwatch.Stop();
            //                     Console.WriteLine("耗时:" + stopwatch.Elapsed);
            //                 };
            //bk.RunWorkerCompleted += delegate
            //                             {
            //                                 Console.WriteLine("全部上传成功!");
            //                             };
            //bk.RunWorkerAsync();
            //Application.Run(new Form1());
            #endregion

            var updater = Updater.CreateUpdaterInstance("http://api.mzc9.com:8081/update/{0}", "update_c.xml");
            //Func<bool?> func = StartApp;
            updater.EnsureNoUpdate();
            Application.Run(new Main());
        }

        static void doLog(QiniuUploadLog qiniuUploadLog)
        {
            Console.WriteLine(string.Format("[{0}].{1}", DateTime.Now.ToString("HH:mm:ss"), qiniuUploadLog.msg));
        }

        static void doResult(QiniuUploadResult result)
        {
            Console.WriteLine(string.Format("[{0}].result:{1} url:{2}", DateTime.Now.ToString("HH:mm:ss"), result.success, result.url));
        }
    }
}
